﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using dhDataAcess.produceLinq.StockLinq;

namespace dhDataAcess.produceDAL.Stock
{
  public   class orderProduceListDAL
    {
         string  tableName = "orderProduceList";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public orderProduceListDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入生产通知单表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int orderProduceListInsert(orderProduceListModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
           // string insertstr = "insert into pbomMaster (mark,updateUser,updateDate,createUser,createDate,checkDate,spr,zbr,awgight,bweight,machineType,custNum,pname) values(@mark,@updateUser,@updateDate,@createUser,@createDate,@checkDate,@spr,@zbr,@awgight,@bweight,@machineType,@custNum,@pname)";
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();

            SqlParameter[] para = {
                                      new SqlParameter ("@mark",row .mark ),
                                      new SqlParameter ("@createDate",row .createDate ),
                                      new SqlParameter ("@createUser",row .createUser ),
                                      new SqlParameter ("@orderStauts",row .orderStauts ),
                                      new SqlParameter ("@producDate",row .producDate ),
                                      new SqlParameter ("@unit",row .unit ),
                                      new SqlParameter ("@qty",row .qty ),
                                      new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                      new SqlParameter ("@produceNo",row .produceNo ),
                                      new SqlParameter ("@gr",row .gr  ),
                                      new SqlParameter ("@m",row .m  ),
                                      new SqlParameter ("@y",row .y  ),
                                      new SqlParameter ("@kg",row .kg )

                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新生产通知单数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int orderProduceListUpdate(orderProduceListModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                      new SqlParameter ("@mark",row .mark ),
                                      new SqlParameter ("@createDate",row .createDate ),
                                      new SqlParameter ("@createUser",row .createUser ),
                                      new SqlParameter ("@orderStauts",row .orderStauts ),
                                      new SqlParameter ("@producDate",row .producDate ),
                                      new SqlParameter ("@unit",row .unit ),
                                      new SqlParameter ("@qty",row .qty ),
                                      new SqlParameter ("@orderDetailNo",row .orderDetailNo ),
                                      new SqlParameter ("@produceNo",row .produceNo ),
                                          new SqlParameter ("@gr",row .gr  ),
                                      new SqlParameter ("@m",row .m  ),
                                      new SqlParameter ("@y",row .y  ),
                                      new SqlParameter ("@kg",row .kg )
                                  };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行生产通知单数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int orderProduceListDel(string produceNo)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                     
                                        new SqlParameter ("@produceNo",produceNo )
                                   };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
